{% extends 'myadmin/index.html' %}

{% block title %}
<title>BookShop-用户编辑</title>
{% endblock %}

{% block con %}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-fl">
                        <font style="vertical-align: inherit;">
                            <font style="vertical-align: inherit;">用户编辑</font>
                        </font>
                    </div>
                    <div class="widget-function am-fr">
                        <a href="javascript:;" class="am-icon-cog"></a>
                    </div>
                </div>

                <div class="widget-body am-fr">
                    <form action="{% url 'myadmin_useredit' userobj.id %}" method="POST" class="am-form tpl-form-line-form" enctype="multipart/form-data">
                        {% csrf_token %}

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">用户名：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="username" value="{{ userobj.username }}" class="tpl-form-input" placeholder="请输入用户名">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">手机号：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="phone" value="{{ userobj.phone }}" minlength="11" class="tpl-form-input" placeholder="请输入手机号">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">性别：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <label for="" class="am-radio-inline">
                                    <input type="radio" name="sex" value="0" {%if userobj.sex == 0%} checked {%endif%}>女
                                </label>
                                <label for="" class="am-radio-inline">
                                    <input type="radio" name="sex" value="1" {%if userobj.sex == 1%} checked {%endif%}>男
                                </label>
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">年龄：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <input type="number" name="age" value="{{ userobj.age }}" min="0" max="120" class="tpl-form-input">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label for="user-weibo" class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">头像：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <div class="am-form-group am-form-file">
                                    <div class="tpl-form-file-img">
                                        <img id="img" src="{{ userobj.face_url }}" alt="">
                                    </div>
                                    <br>
                                    <button type="button" class="am-btn am-btn-danger am-btn-sm">
                                        <i class="am-icon-cloud-upload"></i>
                                        <font style="vertical-align: inherit;">
                                            <font style="vertical-align: inherit;"> 添加头像</font>
                                        </font>
                                    </button>
                                    <input id="face" type="file" name="face" multiple="">
                                </div>
                            </div>
                        </div>
                        <script>
                            // 为上传控件绑定事件（当值发生改变时触发）
                            $('#face').change(function(){
                                // 判断是否选择了图片
                                if(this.files.length == 0){
                                    // 取消了图片选择
                                    $('#img').attr('src','')
                                }else{
                                    // 获取当前用户选择的图片对象
                                    var file = this.files[0]
                                    // 实例化文件读取对象
                                    var read = new FileReader()
                                    // 读取上传的文件数据为DataURL
                                    read.readAsDataURL(file)
                                    // 读取成功后显示图片
                                    read.onload = function(){
                                        $('#img').attr('src',this.result)
                                    }
                                }
                            })
                        </script>

                        <br>
                        <div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3">
                                <button class="am-btn am-btn-primary tpl-btn-bg-color-success ">
                                    <font style="vertical-align: inherit;">
                                        <font style="vertical-align: inherit;">提交</font>
                                    </font>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}